namespace PMS.BLL
{
    using PMS.Common;
    using PMS.DBUtility;
    using PMS.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;
    using System.Text;

    public class UserBLL
    {
        public int Add(User model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into [User](");
            builder.Append("GraduationDate,GraduationSchoole,HighestEducation,Degree,Major,JoinWorkDate,Photo,IsOfficer,Remark,RegistDay,UserName,RegistWay,RegistFrom,RegistTo,OrganID,RegistNo,RegistDate,RegistSummary,RegistRemark,RegistState,RegistType,UserType,Sex,IsHeighWith,JobPositionType,JobPositionName1,JobPositionDate1,JobPositionName2,JobPositionDate2,JobPositionNo,JobPositionDate,JobPositionSummary,JobPositionRemark,Birthday,AdminPosition,EvaluationDate,Position1,PositionLevel1,JobTitle1,PositionStartDate1,PositionEndDate1,PositionNo1,PositionDate1,PositionRemark1,ID,IsDoublePosition,Position2,PositionLevel2,JobTitle2,PositionStartDate2,PositionEndDate2,PositionNo2,PositionDate2,PositionRemark2,Class,Birthplace,ClassDate,IsLeave,LeaveReasion,LeaveDay,LeaveTo,LeaveNo,LeaveDate,LeaveSummary,LeaveRemark,AddUser,Nation,AddDate,UpdateUser,UpdateDate,Backup1,Backup2,Backup3,Backup4,Backup5,Backup6,Backup7,Politics,JoinPartDate");
            builder.Append(") values (");
            builder.Append("@GraduationDate,@GraduationSchoole,@HighestEducation,@Degree,@Major,@JoinWorkDate,@Photo,@IsOfficer,@Remark,@RegistDay,@UserName,@RegistWay,@RegistFrom,@RegistTo,@OrganID,@RegistNo,@RegistDate,@RegistSummary,@RegistRemark,@RegistState,@RegistType,@UserType,@Sex,@IsHeighWith,@JobPositionType,@JobPositionName1,@JobPositionDate1,@JobPositionName2,@JobPositionDate2,@JobPositionNo,@JobPositionDate,@JobPositionSummary,@JobPositionRemark,@Birthday,@AdminPosition,@EvaluationDate,@Position1,@PositionLevel1,@JobTitle1,@PositionStartDate1,@PositionEndDate1,@PositionNo1,@PositionDate1,@PositionRemark1,@ID,@IsDoublePosition,@Position2,@PositionLevel2,@JobTitle2,@PositionStartDate2,@PositionEndDate2,@PositionNo2,@PositionDate2,@PositionRemark2,@Class,@Birthplace,@ClassDate,@IsLeave,@LeaveReasion,@LeaveDay,@LeaveTo,@LeaveNo,@LeaveDate,@LeaveSummary,@LeaveRemark,@AddUser,@Nation,@AddDate,@UpdateUser,@UpdateDate,@Backup1,@Backup2,@Backup3,@Backup4,@Backup5,@Backup6,@Backup7,@Politics,@JoinPartDate");
            builder.Append(") ");
            builder.Append(";select @@IDENTITY");
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@GraduationDate", model.GraduationDate), new SqlParameter("@GraduationSchoole", model.GraduationSchoole), new SqlParameter("@HighestEducation", model.HighestEducation), new SqlParameter("@Degree", model.Degree), new SqlParameter("@Major", model.Major), new SqlParameter("@JoinWorkDate", model.JoinWorkDate), new SqlParameter("@Photo", model.Photo), new SqlParameter("@IsOfficer", model.IsOfficer), new SqlParameter("@Remark", model.Remark), new SqlParameter("@RegistDay", model.RegistDay), new SqlParameter("@UserName", model.UserName), new SqlParameter("@RegistWay", model.RegistWay), new SqlParameter("@RegistFrom", model.RegistFrom), new SqlParameter("@RegistTo", model.RegistTo), new SqlParameter("@OrganID", model.OrganID), new SqlParameter("@RegistNo", model.RegistNo), 
                new SqlParameter("@RegistDate", model.RegistDate), new SqlParameter("@RegistSummary", model.RegistSummary), new SqlParameter("@RegistRemark", model.RegistRemark), new SqlParameter("@RegistState", model.RegistState), new SqlParameter("@RegistType", model.RegistType), new SqlParameter("@UserType", model.UserType), new SqlParameter("@Sex", model.Sex), new SqlParameter("@IsHeighWith", model.IsHeighWith), new SqlParameter("@JobPositionType", model.JobPositionType), new SqlParameter("@JobPositionName1", model.JobPositionName1), new SqlParameter("@JobPositionDate1", model.JobPositionDate1), new SqlParameter("@JobPositionName2", model.JobPositionName2), new SqlParameter("@JobPositionDate2", model.JobPositionDate2), new SqlParameter("@JobPositionNo", model.JobPositionNo), new SqlParameter("@JobPositionDate", model.JobPositionDate), new SqlParameter("@JobPositionSummary", model.JobPositionSummary), 
                new SqlParameter("@JobPositionRemark", model.JobPositionRemark), new SqlParameter("@Birthday", model.Birthday), new SqlParameter("@AdminPosition", model.AdminPosition), new SqlParameter("@EvaluationDate", model.EvaluationDate), new SqlParameter("@Position1", model.Position1), new SqlParameter("@PositionLevel1", model.PositionLevel1), new SqlParameter("@JobTitle1", model.JobTitle1), new SqlParameter("@PositionStartDate1", model.PositionStartDate1), new SqlParameter("@PositionEndDate1", model.PositionEndDate1), new SqlParameter("@PositionNo1", model.PositionNo1), new SqlParameter("@PositionDate1", model.PositionDate1), new SqlParameter("@PositionRemark1", model.PositionRemark1), new SqlParameter("@ID", model.ID), new SqlParameter("@IsDoublePosition", model.IsDoublePosition), new SqlParameter("@Position2", model.Position2), new SqlParameter("@PositionLevel2", model.PositionLevel2), 
                new SqlParameter("@JobTitle2", model.JobTitle2), new SqlParameter("@PositionStartDate2", model.PositionStartDate2), new SqlParameter("@PositionEndDate2", model.PositionEndDate2), new SqlParameter("@PositionNo2", model.PositionNo2), new SqlParameter("@PositionDate2", model.PositionDate2), new SqlParameter("@PositionRemark2", model.PositionRemark2), new SqlParameter("@Class", model.Class), new SqlParameter("@Birthplace", model.Birthplace), new SqlParameter("@ClassDate", model.ClassDate), new SqlParameter("@IsLeave", model.IsLeave), new SqlParameter("@LeaveReasion", model.LeaveReasion), new SqlParameter("@LeaveDay", model.LeaveDay), new SqlParameter("@LeaveTo", model.LeaveTo), new SqlParameter("@LeaveNo", model.LeaveNo), new SqlParameter("@LeaveDate", model.LeaveDate), new SqlParameter("@LeaveSummary", model.LeaveSummary), 
                new SqlParameter("@LeaveRemark", model.LeaveRemark), new SqlParameter("@AddUser", model.AddUser), new SqlParameter("@Nation", model.Nation), new SqlParameter("@AddDate", model.AddDate), new SqlParameter("@UpdateUser", model.UpdateUser), new SqlParameter("@UpdateDate", model.UpdateDate), new SqlParameter("@Backup1", model.Backup1), new SqlParameter("@Backup2", model.Backup2), new SqlParameter("@Backup3", model.Backup3), new SqlParameter("@Backup4", model.Backup4), new SqlParameter("@Backup5", model.Backup5), new SqlParameter("@Backup6", model.Backup6), new SqlParameter("@Backup7", model.Backup7), new SqlParameter("@Politics", model.Politics), new SqlParameter("@JoinPartDate", model.JoinPartDate)
             };
            object single = DBHelper.GetSingle(builder.ToString(), cmdParms);
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }

        public bool Delete(int UserID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from [User] ");
            builder.Append(" where UserID=@UserID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@UserID", SqlDbType.Int, 4) };
            cmdParms[0].Value = UserID;
            return (DBHelper.ExecuteSql(builder.ToString(), cmdParms) > 0);
        }

        public bool DeleteList(string UserIDlist)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from [User] ");
            builder.Append(" where ID in (" + UserIDlist + ")  ");
            return (DBHelper.ExecuteSql(builder.ToString()) > 0);
        }

        public List<User> GetList(string sql, int OrganID = 0)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(sql);
            if (OrganID != 0)
            {
                if (sql.ToLower().IndexOf("where") > 0)
                {
                    builder.Append(" AND OrganID=").Append(OrganID);
                }
                else
                {
                    builder.Append(" WHERE OrganID=").Append(OrganID);
                }
            }
            builder.Append("  Order by SortCode ASC ");
            DataTable table = DBHelper.Query(builder.ToString()).Tables[0];
            User item = null;
            List<User> list = null;
            if (table.Rows.Count > 0)
            {
                list = new List<User>();
                foreach (DataRow row in table.Rows)
                {
                    item = new User();
                    if (row["UserID"].ToString() != "")
                    {
                        item.UserID = int.Parse(row["UserID"].ToString());
                    }
                    if (row["GraduationDate"].ToString() != "")
                    {
                        item.GraduationDate = new DateTime?(DateTime.Parse(row["GraduationDate"].ToString()));
                    }
                    item.GraduationSchoole = row["GraduationSchoole"].ToString();
                    item.HighestEducation = row["HighestEducation"].ToString();
                    item.Degree = row["Degree"].ToString();
                    item.Major = row["Major"].ToString();
                    if (row["JoinWorkDate"].ToString() != "")
                    {
                        item.JoinWorkDate = new DateTime?(DateTime.Parse(row["JoinWorkDate"].ToString()));
                    }
                    item.Photo = row["Photo"].ToString();
                    if (row["IsOfficer"].ToString() != "")
                    {
                        item.IsOfficer = new int?(int.Parse(row["IsOfficer"].ToString()));
                    }
                    item.Remark = row["Remark"].ToString();
                    if (row["RegistDay"].ToString() != "")
                    {
                        item.RegistDay = new DateTime?(DateTime.Parse(row["RegistDay"].ToString()));
                    }
                    item.UserName = row["UserName"].ToString();
                    item.RegistWay = row["RegistWay"].ToString();
                    item.RegistFrom = row["RegistFrom"].ToString();
                    item.RegistTo = row["RegistTo"].ToString();
                    if (row["OrganID"].ToString() != "")
                    {
                        item.OrganID = new int?(int.Parse(row["OrganID"].ToString()));
                    }
                    item.RegistNo = row["RegistNo"].ToString();
                    if (row["RegistDate"].ToString() != "")
                    {
                        item.RegistDate = new DateTime?(DateTime.Parse(row["RegistDate"].ToString()));
                    }
                    item.RegistSummary = row["RegistSummary"].ToString();
                    item.RegistRemark = row["RegistRemark"].ToString();
                    item.RegistState = row["RegistState"].ToString();
                    item.RegistType = row["RegistType"].ToString();
                    item.UserType = row["UserType"].ToString();
                    item.Sex = row["Sex"].ToString();
                    if (row["IsHeighWith"].ToString() != "")
                    {
                        item.IsHeighWith = new int?(int.Parse(row["IsHeighWith"].ToString()));
                    }
                    item.JobPositionType = row["JobPositionType"].ToString();
                    item.JobPositionName1 = row["JobPositionName1"].ToString();
                    if (row["JobPositionDate1"].ToString() != "")
                    {
                        item.JobPositionDate1 = new DateTime?(DateTime.Parse(row["JobPositionDate1"].ToString()));
                    }
                    item.JobPositionName2 = row["JobPositionName2"].ToString();
                    if (row["JobPositionDate2"].ToString() != "")
                    {
                        item.JobPositionDate2 = new DateTime?(DateTime.Parse(row["JobPositionDate2"].ToString()));
                    }
                    item.JobPositionNo = row["JobPositionNo"].ToString();
                    if (row["JobPositionDate"].ToString() != "")
                    {
                        item.JobPositionDate = new DateTime?(DateTime.Parse(row["JobPositionDate"].ToString()));
                    }
                    item.JobPositionSummary = row["JobPositionSummary"].ToString();
                    item.JobPositionRemark = row["JobPositionRemark"].ToString();
                    if (row["Birthday"].ToString() != "")
                    {
                        item.Birthday = new DateTime?(DateTime.Parse(row["Birthday"].ToString()));
                    }
                    item.AdminPosition = row["AdminPosition"].ToString();
                    if (row["EvaluationDate"].ToString() != "")
                    {
                        item.EvaluationDate = new DateTime?(DateTime.Parse(row["EvaluationDate"].ToString()));
                    }
                    item.Position1 = row["Position1"].ToString();
                    item.PositionLevel1 = row["PositionLevel1"].ToString();
                    item.JobTitle1 = row["JobTitle1"].ToString();
                    if (row["PositionStartDate1"].ToString() != "")
                    {
                        item.PositionStartDate1 = new DateTime?(DateTime.Parse(row["PositionStartDate1"].ToString()));
                    }
                    if (row["PositionEndDate1"].ToString() != "")
                    {
                        item.PositionEndDate1 = new DateTime?(DateTime.Parse(row["PositionEndDate1"].ToString()));
                    }
                    item.PositionNo1 = row["PositionNo1"].ToString();
                    if (row["PositionDate1"].ToString() != "")
                    {
                        item.PositionDate1 = new DateTime?(DateTime.Parse(row["PositionDate1"].ToString()));
                    }
                    item.PositionRemark1 = row["PositionRemark1"].ToString();
                    item.ID = row["ID"].ToString();
                    if (row["IsDoublePosition"].ToString() != "")
                    {
                        item.IsDoublePosition = new int?(int.Parse(row["IsDoublePosition"].ToString()));
                    }
                    item.Position2 = row["Position2"].ToString();
                    item.PositionLevel2 = row["PositionLevel2"].ToString();
                    item.JobTitle2 = row["JobTitle2"].ToString();
                    if (row["PositionStartDate2"].ToString() != "")
                    {
                        item.PositionStartDate2 = new DateTime?(DateTime.Parse(row["PositionStartDate2"].ToString()));
                    }
                    if (row["PositionEndDate2"].ToString() != "")
                    {
                        item.PositionEndDate2 = new DateTime?(DateTime.Parse(row["PositionEndDate2"].ToString()));
                    }
                    item.PositionNo2 = row["PositionNo2"].ToString();
                    if (row["PositionDate2"].ToString() != "")
                    {
                        item.PositionDate2 = new DateTime?(DateTime.Parse(row["PositionDate2"].ToString()));
                    }
                    item.PositionRemark2 = row["PositionRemark2"].ToString();
                    item.Class = row["Class"].ToString();
                    item.Birthplace = row["Birthplace"].ToString();
                    if (row["ClassDate"].ToString() != "")
                    {
                        item.ClassDate = new DateTime?(DateTime.Parse(row["ClassDate"].ToString()));
                    }
                    if (row["IsLeave"].ToString() != "")
                    {
                        item.IsLeave = new int?(int.Parse(row["IsLeave"].ToString()));
                    }
                    item.LeaveReasion = row["LeaveReasion"].ToString();
                    if (row["LeaveDay"].ToString() != "")
                    {
                        item.LeaveDay = new DateTime?(DateTime.Parse(row["LeaveDay"].ToString()));
                    }
                    item.LeaveTo = row["LeaveTo"].ToString();
                    item.LeaveNo = row["LeaveNo"].ToString();
                    if (row["LeaveDate"].ToString() != "")
                    {
                        item.LeaveDate = new DateTime?(DateTime.Parse(row["LeaveDate"].ToString()));
                    }
                    item.LeaveSummary = row["LeaveSummary"].ToString();
                    item.LeaveRemark = row["LeaveRemark"].ToString();
                    item.AddUser = row["AddUser"].ToString();
                    item.Nation = row["Nation"].ToString();
                    if (row["AddDate"].ToString() != "")
                    {
                        item.AddDate = new DateTime?(DateTime.Parse(row["AddDate"].ToString()));
                    }
                    item.UpdateUser = row["UpdateUser"].ToString();
                    if (row["UpdateDate"].ToString() != "")
                    {
                        item.UpdateDate = new DateTime?(DateTime.Parse(row["UpdateDate"].ToString()));
                    }
                    item.Backup1 = row["Backup1"].ToString();
                    item.Backup2 = row["Backup2"].ToString();
                    item.Backup3 = row["Backup3"].ToString();
                    item.Backup4 = row["Backup4"].ToString();
                    item.Backup5 = row["Backup5"].ToString();
                    item.Backup6 = row["Backup6"].ToString();
                    item.Backup7 = row["Backup7"].ToString();
                    item.Politics = row["Politics"].ToString();
                    if (row["JoinPartDate"].ToString() != "")
                    {
                        item.JoinPartDate = new DateTime?(DateTime.Parse(row["JoinPartDate"].ToString()));
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public List<User> GetList(int OrganID = 0, bool? isLeave = new bool?(), string keyword = "")
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * ");
            builder.Append(" FROM [User] ");
            builder.Append(" WHERE 1=1 ");
            if (OrganID != 0)
            {
                builder.Append(" AND OrganID=").Append(OrganID);
            }
            if (isLeave.HasValue)
            {
                if (isLeave.Value)
                {
                    builder.Append(" AND isLeave= 1");
                }
                else
                {
                    builder.Append(" AND isLeave= 0");
                }
            }
            if (keyword != "")
            {
                builder.Append(" AND (UserName LIKE '%").Append(keyword).Append("%' OR  ID LIKE '%").Append(keyword).Append("%')");
            }
            builder.Append("  Order by SortCode ASC ");
            DataTable table = DBHelper.Query(builder.ToString()).Tables[0];
            User item = null;
            List<User> list = null;
            if (table.Rows.Count > 0)
            {
                list = new List<User>();
                foreach (DataRow row in table.Rows)
                {
                    item = new User();
                    if (row["UserID"].ToString() != "")
                    {
                        item.UserID = int.Parse(row["UserID"].ToString());
                    }
                    if (row["GraduationDate"].ToString() != "")
                    {
                        item.GraduationDate = new DateTime?(DateTime.Parse(row["GraduationDate"].ToString()));
                    }
                    item.GraduationSchoole = row["GraduationSchoole"].ToString();
                    item.HighestEducation = row["HighestEducation"].ToString();
                    item.Degree = row["Degree"].ToString();
                    item.Major = row["Major"].ToString();
                    if (row["JoinWorkDate"].ToString() != "")
                    {
                        item.JoinWorkDate = new DateTime?(DateTime.Parse(row["JoinWorkDate"].ToString()));
                    }
                    item.Photo = row["Photo"].ToString();
                    if (row["IsOfficer"].ToString() != "")
                    {
                        item.IsOfficer = new int?(int.Parse(row["IsOfficer"].ToString()));
                    }
                    item.Remark = row["Remark"].ToString();
                    if (row["RegistDay"].ToString() != "")
                    {
                        item.RegistDay = new DateTime?(DateTime.Parse(row["RegistDay"].ToString()));
                    }
                    item.UserName = row["UserName"].ToString();
                    item.RegistWay = row["RegistWay"].ToString();
                    item.RegistFrom = row["RegistFrom"].ToString();
                    item.RegistTo = row["RegistTo"].ToString();
                    if (row["OrganID"].ToString() != "")
                    {
                        item.OrganID = new int?(int.Parse(row["OrganID"].ToString()));
                    }
                    item.RegistNo = row["RegistNo"].ToString();
                    if (row["RegistDate"].ToString() != "")
                    {
                        item.RegistDate = new DateTime?(DateTime.Parse(row["RegistDate"].ToString()));
                    }
                    item.RegistSummary = row["RegistSummary"].ToString();
                    item.RegistRemark = row["RegistRemark"].ToString();
                    item.RegistState = row["RegistState"].ToString();
                    item.RegistType = row["RegistType"].ToString();
                    item.UserType = row["UserType"].ToString();
                    item.Sex = row["Sex"].ToString();
                    if (row["IsHeighWith"].ToString() != "")
                    {
                        item.IsHeighWith = new int?(int.Parse(row["IsHeighWith"].ToString()));
                    }
                    item.JobPositionType = row["JobPositionType"].ToString();
                    item.JobPositionName1 = row["JobPositionName1"].ToString();
                    if (row["JobPositionDate1"].ToString() != "")
                    {
                        item.JobPositionDate1 = new DateTime?(DateTime.Parse(row["JobPositionDate1"].ToString()));
                    }
                    item.JobPositionName2 = row["JobPositionName2"].ToString();
                    if (row["JobPositionDate2"].ToString() != "")
                    {
                        item.JobPositionDate2 = new DateTime?(DateTime.Parse(row["JobPositionDate2"].ToString()));
                    }
                    item.JobPositionNo = row["JobPositionNo"].ToString();
                    if (row["JobPositionDate"].ToString() != "")
                    {
                        item.JobPositionDate = new DateTime?(DateTime.Parse(row["JobPositionDate"].ToString()));
                    }
                    item.JobPositionSummary = row["JobPositionSummary"].ToString();
                    item.JobPositionRemark = row["JobPositionRemark"].ToString();
                    if (row["Birthday"].ToString() != "")
                    {
                        item.Birthday = new DateTime?(DateTime.Parse(row["Birthday"].ToString()));
                    }
                    item.AdminPosition = row["AdminPosition"].ToString();
                    if (row["EvaluationDate"].ToString() != "")
                    {
                        item.EvaluationDate = new DateTime?(DateTime.Parse(row["EvaluationDate"].ToString()));
                    }
                    item.Position1 = row["Position1"].ToString();
                    item.PositionLevel1 = row["PositionLevel1"].ToString();
                    item.JobTitle1 = row["JobTitle1"].ToString();
                    if (row["PositionStartDate1"].ToString() != "")
                    {
                        item.PositionStartDate1 = new DateTime?(DateTime.Parse(row["PositionStartDate1"].ToString()));
                    }
                    if (row["PositionEndDate1"].ToString() != "")
                    {
                        item.PositionEndDate1 = new DateTime?(DateTime.Parse(row["PositionEndDate1"].ToString()));
                    }
                    item.PositionNo1 = row["PositionNo1"].ToString();
                    if (row["PositionDate1"].ToString() != "")
                    {
                        item.PositionDate1 = new DateTime?(DateTime.Parse(row["PositionDate1"].ToString()));
                    }
                    item.PositionRemark1 = row["PositionRemark1"].ToString();
                    item.ID = row["ID"].ToString();
                    if (row["IsDoublePosition"].ToString() != "")
                    {
                        item.IsDoublePosition = new int?(int.Parse(row["IsDoublePosition"].ToString()));
                    }
                    item.Position2 = row["Position2"].ToString();
                    item.PositionLevel2 = row["PositionLevel2"].ToString();
                    item.JobTitle2 = row["JobTitle2"].ToString();
                    if (row["PositionStartDate2"].ToString() != "")
                    {
                        item.PositionStartDate2 = new DateTime?(DateTime.Parse(row["PositionStartDate2"].ToString()));
                    }
                    if (row["PositionEndDate2"].ToString() != "")
                    {
                        item.PositionEndDate2 = new DateTime?(DateTime.Parse(row["PositionEndDate2"].ToString()));
                    }
                    item.PositionNo2 = row["PositionNo2"].ToString();
                    if (row["PositionDate2"].ToString() != "")
                    {
                        item.PositionDate2 = new DateTime?(DateTime.Parse(row["PositionDate2"].ToString()));
                    }
                    item.PositionRemark2 = row["PositionRemark2"].ToString();
                    item.Class = row["Class"].ToString();
                    item.Birthplace = row["Birthplace"].ToString();
                    if (row["ClassDate"].ToString() != "")
                    {
                        item.ClassDate = new DateTime?(DateTime.Parse(row["ClassDate"].ToString()));
                    }
                    if (row["IsLeave"].ToString() != "")
                    {
                        item.IsLeave = new int?(int.Parse(row["IsLeave"].ToString()));
                    }
                    item.LeaveReasion = row["LeaveReasion"].ToString();
                    if (row["LeaveDay"].ToString() != "")
                    {
                        item.LeaveDay = new DateTime?(DateTime.Parse(row["LeaveDay"].ToString()));
                    }
                    item.LeaveTo = row["LeaveTo"].ToString();
                    item.LeaveNo = row["LeaveNo"].ToString();
                    if (row["LeaveDate"].ToString() != "")
                    {
                        item.LeaveDate = new DateTime?(DateTime.Parse(row["LeaveDate"].ToString()));
                    }
                    item.LeaveSummary = row["LeaveSummary"].ToString();
                    item.LeaveRemark = row["LeaveRemark"].ToString();
                    item.AddUser = row["AddUser"].ToString();
                    item.Nation = row["Nation"].ToString();
                    if (row["AddDate"].ToString() != "")
                    {
                        item.AddDate = new DateTime?(DateTime.Parse(row["AddDate"].ToString()));
                    }
                    item.UpdateUser = row["UpdateUser"].ToString();
                    if (row["UpdateDate"].ToString() != "")
                    {
                        item.UpdateDate = new DateTime?(DateTime.Parse(row["UpdateDate"].ToString()));
                    }
                    item.Backup1 = row["Backup1"].ToString();
                    item.Backup2 = row["Backup2"].ToString();
                    item.Backup3 = row["Backup3"].ToString();
                    item.Backup4 = row["Backup4"].ToString();
                    item.Backup5 = row["Backup5"].ToString();
                    item.Backup6 = row["Backup6"].ToString();
                    item.Backup7 = row["Backup7"].ToString();
                    item.Politics = row["Politics"].ToString();
                    if (row["JoinPartDate"].ToString() != "")
                    {
                        item.JoinPartDate = new DateTime?(DateTime.Parse(row["JoinPartDate"].ToString()));
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public User GetModel(int UserID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" SELECT *  ");
            builder.Append("  from [User] ");
            builder.Append(" where UserID=@UserID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@UserID", SqlDbType.Int, 4) };
            cmdParms[0].Value = UserID;
            User user = new User();
            DataSet set = DBHelper.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count > 0)
            {
                DataRow row = set.Tables[0].Rows[0];
                if (row["UserID"].ToString() != "")
                {
                    user.UserID = int.Parse(row["UserID"].ToString());
                }
                if (row["GraduationDate"].ToString() != "")
                {
                    user.GraduationDate = new DateTime?(DateTime.Parse(row["GraduationDate"].ToString()));
                }
                user.GraduationSchoole = row["GraduationSchoole"].ToString();
                user.HighestEducation = row["HighestEducation"].ToString();
                user.Degree = row["Degree"].ToString();
                user.Major = row["Major"].ToString();
                if (row["JoinWorkDate"].ToString() != "")
                {
                    user.JoinWorkDate = new DateTime?(DateTime.Parse(row["JoinWorkDate"].ToString()));
                }
                user.Photo = row["Photo"].ToString();
                if (row["IsOfficer"].ToString() != "")
                {
                    user.IsOfficer = new int?(int.Parse(row["IsOfficer"].ToString()));
                }
                user.Remark = row["Remark"].ToString();
                if (row["RegistDay"].ToString() != "")
                {
                    user.RegistDay = new DateTime?(DateTime.Parse(row["RegistDay"].ToString()));
                }
                user.UserName = row["UserName"].ToString();
                user.RegistWay = row["RegistWay"].ToString();
                user.RegistFrom = row["RegistFrom"].ToString();
                user.RegistTo = row["RegistTo"].ToString();
                if (row["OrganID"].ToString() != "")
                {
                    user.OrganID = new int?(int.Parse(row["OrganID"].ToString()));
                }
                user.RegistNo = row["RegistNo"].ToString();
                if (row["RegistDate"].ToString() != "")
                {
                    user.RegistDate = new DateTime?(DateTime.Parse(row["RegistDate"].ToString()));
                }
                user.RegistSummary = row["RegistSummary"].ToString();
                user.RegistRemark = row["RegistRemark"].ToString();
                user.RegistState = row["RegistState"].ToString();
                user.RegistType = row["RegistType"].ToString();
                user.UserType = row["UserType"].ToString();
                user.Sex = row["Sex"].ToString();
                if (row["IsHeighWith"].ToString() != "")
                {
                    user.IsHeighWith = new int?(int.Parse(row["IsHeighWith"].ToString()));
                }
                user.JobPositionType = row["JobPositionType"].ToString();
                user.JobPositionName1 = row["JobPositionName1"].ToString();
                if (row["JobPositionDate1"].ToString() != "")
                {
                    user.JobPositionDate1 = new DateTime?(DateTime.Parse(row["JobPositionDate1"].ToString()));
                }
                user.JobPositionName2 = row["JobPositionName2"].ToString();
                if (row["JobPositionDate2"].ToString() != "")
                {
                    user.JobPositionDate2 = new DateTime?(DateTime.Parse(row["JobPositionDate2"].ToString()));
                }
                user.JobPositionNo = row["JobPositionNo"].ToString();
                if (row["JobPositionDate"].ToString() != "")
                {
                    user.JobPositionDate = new DateTime?(DateTime.Parse(row["JobPositionDate"].ToString()));
                }
                user.JobPositionSummary = row["JobPositionSummary"].ToString();
                user.JobPositionRemark = row["JobPositionRemark"].ToString();
                if (row["Birthday"].ToString() != "")
                {
                    user.Birthday = new DateTime?(DateTime.Parse(row["Birthday"].ToString()));
                }
                user.AdminPosition = row["AdminPosition"].ToString();
                if (row["EvaluationDate"].ToString() != "")
                {
                    user.EvaluationDate = new DateTime?(DateTime.Parse(row["EvaluationDate"].ToString()));
                }
                user.Position1 = row["Position1"].ToString();
                user.PositionLevel1 = row["PositionLevel1"].ToString();
                user.JobTitle1 = row["JobTitle1"].ToString();
                if (row["PositionStartDate1"].ToString() != "")
                {
                    user.PositionStartDate1 = new DateTime?(DateTime.Parse(row["PositionStartDate1"].ToString()));
                }
                if (row["PositionEndDate1"].ToString() != "")
                {
                    user.PositionEndDate1 = new DateTime?(DateTime.Parse(row["PositionEndDate1"].ToString()));
                }
                user.PositionNo1 = row["PositionNo1"].ToString();
                if (row["PositionDate1"].ToString() != "")
                {
                    user.PositionDate1 = new DateTime?(DateTime.Parse(row["PositionDate1"].ToString()));
                }
                user.PositionRemark1 = row["PositionRemark1"].ToString();
                user.ID = row["ID"].ToString();
                if (row["IsDoublePosition"].ToString() != "")
                {
                    user.IsDoublePosition = new int?(int.Parse(row["IsDoublePosition"].ToString()));
                }
                user.Position2 = row["Position2"].ToString();
                user.PositionLevel2 = row["PositionLevel2"].ToString();
                user.JobTitle2 = row["JobTitle2"].ToString();
                if (row["PositionStartDate2"].ToString() != "")
                {
                    user.PositionStartDate2 = new DateTime?(DateTime.Parse(row["PositionStartDate2"].ToString()));
                }
                if (row["PositionEndDate2"].ToString() != "")
                {
                    user.PositionEndDate2 = new DateTime?(DateTime.Parse(row["PositionEndDate2"].ToString()));
                }
                user.PositionNo2 = row["PositionNo2"].ToString();
                if (row["PositionDate2"].ToString() != "")
                {
                    user.PositionDate2 = new DateTime?(DateTime.Parse(row["PositionDate2"].ToString()));
                }
                user.PositionRemark2 = row["PositionRemark2"].ToString();
                user.Class = row["Class"].ToString();
                user.Birthplace = row["Birthplace"].ToString();
                if (row["ClassDate"].ToString() != "")
                {
                    user.ClassDate = new DateTime?(DateTime.Parse(row["ClassDate"].ToString()));
                }
                if (row["IsLeave"].ToString() != "")
                {
                    user.IsLeave = new int?(int.Parse(row["IsLeave"].ToString()));
                }
                user.LeaveReasion = row["LeaveReasion"].ToString();
                if (row["LeaveDay"].ToString() != "")
                {
                    user.LeaveDay = new DateTime?(DateTime.Parse(row["LeaveDay"].ToString()));
                }
                user.LeaveTo = row["LeaveTo"].ToString();
                user.LeaveNo = row["LeaveNo"].ToString();
                if (row["LeaveDate"].ToString() != "")
                {
                    user.LeaveDate = new DateTime?(DateTime.Parse(row["LeaveDate"].ToString()));
                }
                user.LeaveSummary = row["LeaveSummary"].ToString();
                user.LeaveRemark = row["LeaveRemark"].ToString();
                user.AddUser = row["AddUser"].ToString();
                user.Nation = row["Nation"].ToString();
                if (row["AddDate"].ToString() != "")
                {
                    user.AddDate = new DateTime?(DateTime.Parse(row["AddDate"].ToString()));
                }
                user.UpdateUser = row["UpdateUser"].ToString();
                if (row["UpdateDate"].ToString() != "")
                {
                    user.UpdateDate = new DateTime?(DateTime.Parse(row["UpdateDate"].ToString()));
                }
                user.Backup1 = row["Backup1"].ToString();
                user.Backup2 = row["Backup2"].ToString();
                user.Backup3 = row["Backup3"].ToString();
                user.Backup4 = row["Backup4"].ToString();
                user.Backup5 = row["Backup5"].ToString();
                user.Backup6 = row["Backup6"].ToString();
                user.Backup7 = row["Backup7"].ToString();
                user.Politics = row["Politics"].ToString();
                if (row["JoinPartDate"].ToString() != "")
                {
                    user.JoinPartDate = new DateTime?(DateTime.Parse(row["JoinPartDate"].ToString()));
                }
                return user;
            }
            return null;
        }

        public User GetModel(string ID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" SELECT *  ");
            builder.Append("  from [User] ");
            builder.Append(" where ID=@ID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@ID", ID) };
            User user = new User();
            DataSet set = DBHelper.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count > 0)
            {
                DataRow row = set.Tables[0].Rows[0];
                if (row["UserID"].ToString() != "")
                {
                    user.UserID = int.Parse(row["UserID"].ToString());
                }
                if (row["GraduationDate"].ToString() != "")
                {
                    user.GraduationDate = new DateTime?(DateTime.Parse(row["GraduationDate"].ToString()));
                }
                user.GraduationSchoole = row["GraduationSchoole"].ToString();
                user.HighestEducation = row["HighestEducation"].ToString();
                user.Degree = row["Degree"].ToString();
                user.Major = row["Major"].ToString();
                if (row["JoinWorkDate"].ToString() != "")
                {
                    user.JoinWorkDate = new DateTime?(DateTime.Parse(row["JoinWorkDate"].ToString()));
                }
                user.Photo = row["Photo"].ToString();
                if (row["IsOfficer"].ToString() != "")
                {
                    user.IsOfficer = new int?(int.Parse(row["IsOfficer"].ToString()));
                }
                user.Remark = row["Remark"].ToString();
                if (row["RegistDay"].ToString() != "")
                {
                    user.RegistDay = new DateTime?(DateTime.Parse(row["RegistDay"].ToString()));
                }
                user.UserName = row["UserName"].ToString();
                user.RegistWay = row["RegistWay"].ToString();
                user.RegistFrom = row["RegistFrom"].ToString();
                user.RegistTo = row["RegistTo"].ToString();
                if (row["OrganID"].ToString() != "")
                {
                    user.OrganID = new int?(int.Parse(row["OrganID"].ToString()));
                }
                user.RegistNo = row["RegistNo"].ToString();
                if (row["RegistDate"].ToString() != "")
                {
                    user.RegistDate = new DateTime?(DateTime.Parse(row["RegistDate"].ToString()));
                }
                user.RegistSummary = row["RegistSummary"].ToString();
                user.RegistRemark = row["RegistRemark"].ToString();
                user.RegistState = row["RegistState"].ToString();
                user.RegistType = row["RegistType"].ToString();
                user.UserType = row["UserType"].ToString();
                user.Sex = row["Sex"].ToString();
                if (row["IsHeighWith"].ToString() != "")
                {
                    user.IsHeighWith = new int?(int.Parse(row["IsHeighWith"].ToString()));
                }
                user.JobPositionType = row["JobPositionType"].ToString();
                user.JobPositionName1 = row["JobPositionName1"].ToString();
                if (row["JobPositionDate1"].ToString() != "")
                {
                    user.JobPositionDate1 = new DateTime?(DateTime.Parse(row["JobPositionDate1"].ToString()));
                }
                user.JobPositionName2 = row["JobPositionName2"].ToString();
                if (row["JobPositionDate2"].ToString() != "")
                {
                    user.JobPositionDate2 = new DateTime?(DateTime.Parse(row["JobPositionDate2"].ToString()));
                }
                user.JobPositionNo = row["JobPositionNo"].ToString();
                if (row["JobPositionDate"].ToString() != "")
                {
                    user.JobPositionDate = new DateTime?(DateTime.Parse(row["JobPositionDate"].ToString()));
                }
                user.JobPositionSummary = row["JobPositionSummary"].ToString();
                user.JobPositionRemark = row["JobPositionRemark"].ToString();
                if (row["Birthday"].ToString() != "")
                {
                    user.Birthday = new DateTime?(DateTime.Parse(row["Birthday"].ToString()));
                }
                user.AdminPosition = row["AdminPosition"].ToString();
                if (row["EvaluationDate"].ToString() != "")
                {
                    user.EvaluationDate = new DateTime?(DateTime.Parse(row["EvaluationDate"].ToString()));
                }
                user.Position1 = row["Position1"].ToString();
                user.PositionLevel1 = row["PositionLevel1"].ToString();
                user.JobTitle1 = row["JobTitle1"].ToString();
                if (row["PositionStartDate1"].ToString() != "")
                {
                    user.PositionStartDate1 = new DateTime?(DateTime.Parse(row["PositionStartDate1"].ToString()));
                }
                if (row["PositionEndDate1"].ToString() != "")
                {
                    user.PositionEndDate1 = new DateTime?(DateTime.Parse(row["PositionEndDate1"].ToString()));
                }
                user.PositionNo1 = row["PositionNo1"].ToString();
                if (row["PositionDate1"].ToString() != "")
                {
                    user.PositionDate1 = new DateTime?(DateTime.Parse(row["PositionDate1"].ToString()));
                }
                user.PositionRemark1 = row["PositionRemark1"].ToString();
                user.ID = row["ID"].ToString();
                if (row["IsDoublePosition"].ToString() != "")
                {
                    user.IsDoublePosition = new int?(int.Parse(row["IsDoublePosition"].ToString()));
                }
                user.Position2 = row["Position2"].ToString();
                user.PositionLevel2 = row["PositionLevel2"].ToString();
                user.JobTitle2 = row["JobTitle2"].ToString();
                if (row["PositionStartDate2"].ToString() != "")
                {
                    user.PositionStartDate2 = new DateTime?(DateTime.Parse(row["PositionStartDate2"].ToString()));
                }
                if (row["PositionEndDate2"].ToString() != "")
                {
                    user.PositionEndDate2 = new DateTime?(DateTime.Parse(row["PositionEndDate2"].ToString()));
                }
                user.PositionNo2 = row["PositionNo2"].ToString();
                if (row["PositionDate2"].ToString() != "")
                {
                    user.PositionDate2 = new DateTime?(DateTime.Parse(row["PositionDate2"].ToString()));
                }
                user.PositionRemark2 = row["PositionRemark2"].ToString();
                user.Class = row["Class"].ToString();
                user.Birthplace = row["Birthplace"].ToString();
                if (row["ClassDate"].ToString() != "")
                {
                    user.ClassDate = new DateTime?(DateTime.Parse(row["ClassDate"].ToString()));
                }
                if (row["IsLeave"].ToString() != "")
                {
                    user.IsLeave = new int?(int.Parse(row["IsLeave"].ToString()));
                }
                user.LeaveReasion = row["LeaveReasion"].ToString();
                if (row["LeaveDay"].ToString() != "")
                {
                    user.LeaveDay = new DateTime?(DateTime.Parse(row["LeaveDay"].ToString()));
                }
                user.LeaveTo = row["LeaveTo"].ToString();
                user.LeaveNo = row["LeaveNo"].ToString();
                if (row["LeaveDate"].ToString() != "")
                {
                    user.LeaveDate = new DateTime?(DateTime.Parse(row["LeaveDate"].ToString()));
                }
                user.LeaveSummary = row["LeaveSummary"].ToString();
                user.LeaveRemark = row["LeaveRemark"].ToString();
                user.AddUser = row["AddUser"].ToString();
                user.Nation = row["Nation"].ToString();
                if (row["AddDate"].ToString() != "")
                {
                    user.AddDate = new DateTime?(DateTime.Parse(row["AddDate"].ToString()));
                }
                user.UpdateUser = row["UpdateUser"].ToString();
                if (row["UpdateDate"].ToString() != "")
                {
                    user.UpdateDate = new DateTime?(DateTime.Parse(row["UpdateDate"].ToString()));
                }
                user.Backup1 = row["Backup1"].ToString();
                user.Backup2 = row["Backup2"].ToString();
                user.Backup3 = row["Backup3"].ToString();
                user.Backup4 = row["Backup4"].ToString();
                user.Backup5 = row["Backup5"].ToString();
                user.Backup6 = row["Backup6"].ToString();
                user.Backup7 = row["Backup7"].ToString();
                user.Politics = row["Politics"].ToString();
                if (row["JoinPartDate"].ToString() != "")
                {
                    user.JoinPartDate = new DateTime?(DateTime.Parse(row["JoinPartDate"].ToString()));
                }
                return user;
            }
            return null;
        }

        public DataTable GetNameList(int OrganID = 0)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(" select UserID,UserName,SortCode ");
            builder.Append(" FROM [User] ");
            builder.Append(" WHERE 1=1 ");
            if (OrganID != 0)
            {
                builder.Append(" AND OrganID=").Append(OrganID);
            }
            builder.Append("  Order by SortCode ASC ");
            DataTable table = DBHelper.Query(builder.ToString()).Tables[0];
            if (table.Rows.Count > 0)
            {
                return table;
            }
            return null;
        }

        public bool Update(User model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update [User] set ");
            builder.Append(" GraduationDate = @GraduationDate , ");
            builder.Append(" GraduationSchoole = @GraduationSchoole , ");
            builder.Append(" HighestEducation = @HighestEducation , ");
            builder.Append(" Degree = @Degree , ");
            builder.Append(" Major = @Major , ");
            builder.Append(" JoinWorkDate = @JoinWorkDate , ");
            builder.Append(" Photo = @Photo , ");
            builder.Append(" IsOfficer = @IsOfficer , ");
            builder.Append(" Remark = @Remark , ");
            builder.Append(" RegistDay = @RegistDay , ");
            builder.Append(" UserName = @UserName , ");
            builder.Append(" RegistWay = @RegistWay , ");
            builder.Append(" RegistFrom = @RegistFrom , ");
            builder.Append(" RegistTo = @RegistTo , ");
            builder.Append(" OrganID = @OrganID , ");
            builder.Append(" RegistNo = @RegistNo , ");
            builder.Append(" RegistDate = @RegistDate , ");
            builder.Append(" RegistSummary = @RegistSummary , ");
            builder.Append(" RegistRemark = @RegistRemark , ");
            builder.Append(" RegistState = @RegistState , ");
            builder.Append(" RegistType = @RegistType , ");
            builder.Append(" UserType = @UserType , ");
            builder.Append(" Sex = @Sex , ");
            builder.Append(" IsHeighWith = @IsHeighWith , ");
            builder.Append(" JobPositionType = @JobPositionType , ");
            builder.Append(" JobPositionName1 = @JobPositionName1 , ");
            builder.Append(" JobPositionDate1 = @JobPositionDate1 , ");
            builder.Append(" JobPositionName2 = @JobPositionName2 , ");
            builder.Append(" JobPositionDate2 = @JobPositionDate2 , ");
            builder.Append(" JobPositionNo = @JobPositionNo , ");
            builder.Append(" JobPositionDate = @JobPositionDate , ");
            builder.Append(" JobPositionSummary = @JobPositionSummary , ");
            builder.Append(" JobPositionRemark = @JobPositionRemark , ");
            builder.Append(" Birthday = @Birthday , ");
            builder.Append(" AdminPosition = @AdminPosition , ");
            builder.Append(" EvaluationDate = @EvaluationDate , ");
            builder.Append(" Position1 = @Position1 , ");
            builder.Append(" PositionLevel1 = @PositionLevel1 , ");
            builder.Append(" JobTitle1 = @JobTitle1 , ");
            builder.Append(" PositionStartDate1 = @PositionStartDate1 , ");
            builder.Append(" PositionEndDate1 = @PositionEndDate1 , ");
            builder.Append(" PositionNo1 = @PositionNo1 , ");
            builder.Append(" PositionDate1 = @PositionDate1 , ");
            builder.Append(" PositionRemark1 = @PositionRemark1 , ");
            builder.Append(" ID = @ID , ");
            builder.Append(" IsDoublePosition = @IsDoublePosition , ");
            builder.Append(" Position2 = @Position2 , ");
            builder.Append(" PositionLevel2 = @PositionLevel2 , ");
            builder.Append(" JobTitle2 = @JobTitle2 , ");
            builder.Append(" PositionStartDate2 = @PositionStartDate2 , ");
            builder.Append(" PositionEndDate2 = @PositionEndDate2 , ");
            builder.Append(" PositionNo2 = @PositionNo2 , ");
            builder.Append(" PositionDate2 = @PositionDate2 , ");
            builder.Append(" PositionRemark2 = @PositionRemark2 , ");
            builder.Append(" Class = @Class , ");
            builder.Append(" Birthplace = @Birthplace , ");
            builder.Append(" ClassDate = @ClassDate , ");
            builder.Append(" IsLeave = @IsLeave , ");
            builder.Append(" LeaveReasion = @LeaveReasion , ");
            builder.Append(" LeaveDay = @LeaveDay , ");
            builder.Append(" LeaveTo = @LeaveTo , ");
            builder.Append(" LeaveNo = @LeaveNo , ");
            builder.Append(" LeaveDate = @LeaveDate , ");
            builder.Append(" LeaveSummary = @LeaveSummary , ");
            builder.Append(" LeaveRemark = @LeaveRemark , ");
            builder.Append(" AddUser = @AddUser , ");
            builder.Append(" Nation = @Nation , ");
            builder.Append(" AddDate = @AddDate , ");
            builder.Append(" UpdateUser = @UpdateUser , ");
            builder.Append(" UpdateDate = @UpdateDate , ");
            builder.Append(" Backup1 = @Backup1 , ");
            builder.Append(" Backup2 = @Backup2 , ");
            builder.Append(" Backup3 = @Backup3 , ");
            builder.Append(" Backup4 = @Backup4 , ");
            builder.Append(" Backup5 = @Backup5 , ");
            builder.Append(" Backup6 = @Backup6 , ");
            builder.Append(" Backup7 = @Backup7 , ");
            builder.Append(" Politics = @Politics , ");
            builder.Append(" JoinPartDate = @JoinPartDate  ");
            builder.Append(" where UserID=@UserID ");
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@UserID", model.UserID), new SqlParameter("@GraduationDate", model.GraduationDate), new SqlParameter("@GraduationSchoole", model.GraduationSchoole), new SqlParameter("@HighestEducation", model.HighestEducation), new SqlParameter("@Degree", model.Degree), new SqlParameter("@Major", model.Major), new SqlParameter("@JoinWorkDate", model.JoinWorkDate), new SqlParameter("@Photo", model.Photo), new SqlParameter("@IsOfficer", model.IsOfficer), new SqlParameter("@Remark", model.Remark), new SqlParameter("@RegistDay", model.RegistDay), new SqlParameter("@UserName", model.UserName), new SqlParameter("@RegistWay", model.RegistWay), new SqlParameter("@RegistFrom", model.RegistFrom), new SqlParameter("@RegistTo", model.RegistTo), new SqlParameter("@OrganID", model.OrganID), 
                new SqlParameter("@RegistNo", model.RegistNo), new SqlParameter("@RegistDate", model.RegistDate), new SqlParameter("@RegistSummary", model.RegistSummary), new SqlParameter("@RegistRemark", model.RegistRemark), new SqlParameter("@RegistState", model.RegistState), new SqlParameter("@RegistType", model.RegistType), new SqlParameter("@UserType", model.UserType), new SqlParameter("@Sex", model.Sex), new SqlParameter("@IsHeighWith", model.IsHeighWith), new SqlParameter("@JobPositionType", model.JobPositionType), new SqlParameter("@JobPositionName1", model.JobPositionName1), new SqlParameter("@JobPositionDate1", model.JobPositionDate1), new SqlParameter("@JobPositionName2", model.JobPositionName2), new SqlParameter("@JobPositionDate2", model.JobPositionDate2), new SqlParameter("@JobPositionNo", model.JobPositionNo), new SqlParameter("@JobPositionDate", model.JobPositionDate), 
                new SqlParameter("@JobPositionSummary", model.JobPositionSummary), new SqlParameter("@JobPositionRemark", model.JobPositionRemark), new SqlParameter("@Birthday", model.Birthday), new SqlParameter("@AdminPosition", model.AdminPosition), new SqlParameter("@EvaluationDate", model.EvaluationDate), new SqlParameter("@Position1", model.Position1), new SqlParameter("@PositionLevel1", model.PositionLevel1), new SqlParameter("@JobTitle1", model.JobTitle1), new SqlParameter("@PositionStartDate1", model.PositionStartDate1), new SqlParameter("@PositionEndDate1", model.PositionEndDate1), new SqlParameter("@PositionNo1", model.PositionNo1), new SqlParameter("@PositionDate1", model.PositionDate1), new SqlParameter("@PositionRemark1", model.PositionRemark1), new SqlParameter("@ID", model.ID), new SqlParameter("@IsDoublePosition", model.IsDoublePosition), new SqlParameter("@Position2", model.Position2), 
                new SqlParameter("@PositionLevel2", model.PositionLevel2), new SqlParameter("@JobTitle2", model.JobTitle2), new SqlParameter("@PositionStartDate2", model.PositionStartDate2), new SqlParameter("@PositionEndDate2", model.PositionEndDate2), new SqlParameter("@PositionNo2", model.PositionNo2), new SqlParameter("@PositionDate2", model.PositionDate2), new SqlParameter("@PositionRemark2", model.PositionRemark2), new SqlParameter("@Class", model.Class), new SqlParameter("@Birthplace", model.Birthplace), new SqlParameter("@ClassDate", model.ClassDate), new SqlParameter("@IsLeave", model.IsLeave), new SqlParameter("@LeaveReasion", model.LeaveReasion), new SqlParameter("@LeaveDay", model.LeaveDay), new SqlParameter("@LeaveTo", model.LeaveTo), new SqlParameter("@LeaveNo", model.LeaveNo), new SqlParameter("@LeaveDate", model.LeaveDate), 
                new SqlParameter("@LeaveSummary", model.LeaveSummary), new SqlParameter("@LeaveRemark", model.LeaveRemark), new SqlParameter("@AddUser", model.AddUser), new SqlParameter("@Nation", model.Nation), new SqlParameter("@AddDate", model.AddDate), new SqlParameter("@UpdateUser", model.UpdateUser), new SqlParameter("@UpdateDate", model.UpdateDate), new SqlParameter("@Backup1", model.Backup1), new SqlParameter("@Backup2", model.Backup2), new SqlParameter("@Backup3", model.Backup3), new SqlParameter("@Backup4", model.Backup4), new SqlParameter("@Backup5", model.Backup5), new SqlParameter("@Backup6", model.Backup6), new SqlParameter("@Backup7", model.Backup7), new SqlParameter("@Politics", model.Politics), new SqlParameter("@JoinPartDate", model.JoinPartDate)
             };
            int num = 0;
            try
            {
                num = DBHelper.ExecuteSql(builder.ToString(), cmdParms);
            }
            catch (Exception exception)
            {
                Log.Write(exception.Message);
                return false;
            }
            return (num > 0);
        }

        public bool UpdateSort(int userid, int sortCode)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update [User] set ");
            builder.Append(" SortCode = @SortCode  ");
            builder.Append(" WHERE UserID = @UserID ");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@UserID", userid), new SqlParameter("@SortCode", sortCode) };
            return (DBHelper.ExecuteSql(builder.ToString(), cmdParms) > 0);
        }
    }
}

